CMD:hangup(playerid, params[])
{
	if(GetPVarInt(playerid, "CALLING_TO") == -1) return 1;
	new id = GetPVarInt(playerid, "CALLING_TO");
	SendClientMessage(id, COLOR_GREY, "They hangup the call...");
	SetPlayerSpecialAction(id, SPECIAL_ACTION_STOPUSECELLPHONE);
	SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
	SetPVarInt(playerid, "CALLING_TO", -1);
	SetPVarInt(id, "CALLING_TO", -1);
	SetPVarInt(playerid, "ON_PHONE", 0);
	SetPVarInt(id, "ON_PHONE", 0);
	return true;
}

CMD:addgps(playerid, params[])
{
   if(strlen(params) < 2) return SendClientMessage(playerid, COLOR_RED, "{FF0000}USAGE: {FFFFFF}/addgps <name>");
   new Float:Pos[3];
   GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
   format(query, sizeof(query), "INSERT INTO gps (Place, X, Y, Z) VALUES ('%s', '%f', '%f', '%f')", params, Pos[0], Pos[1], Pos[2]);
   mysql_query(query);
   format(query, 128, "%s has been added to GPS places", params);
   ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_MSGBOX, "GPS", query, "Close", "");
   return true;
}

CMD:pickupweapon(playerid)
{
    foreach(Weapons, wepID)
	{
        if(IsPlayerInRangeOfPoint(playerid, 1.5, WeaponInfo[wepID][wPos][0], WeaponInfo[wepID][wPos][1], WeaponInfo[wepID][wPos][2]))
		{
			new me_str[128];
			GetPlayerName(playerid, PlayerName, 24);

            GivePlayerWeapon(playerid, WeaponInfo[wepID][wDropped], WeaponInfo[wepID][wAmmo]);

            WeaponInfo[wepID][wPos][0] = 0.0;
            WeaponInfo[wepID][wPos][1] = 0.0;
            WeaponInfo[wepID][wPos][2] = 0.0;

            DestroyObject(WeaponInfo[wepID][wObjectID]);

            format(me_str, 128, "%s takes %s from ground", PlayerName, GetPlayerWeaponName(WeaponInfo[wepID][wDropped]));
            SendLocalMessage(playerid, me_str, 20.0, COLOR_ME);

            Iter_Remove(Weapons, wepID);
            return 1;
        }
    }
    return 1;
}


CMD:dropweapon(playerid)
{
    new gunID = GetPlayerWeapon(playerid);
    new gunAmmo = GetPlayerAmmo(playerid);
    new WID;

    if(gunID == 0 && gunAmmo == 0) return 1;
    new me_str[128];
    GetPlayerName(playerid, PlayerName, 24);

    format(me_str, sizeof(me_str), "%s  drops his %s", PlayerName, GetPlayerWeaponName(gunID));
    SendLocalMessage(playerid, me_str, 20.0, COLOR_ME);
    RemovePlayerWeapon(playerid, gunID);

    Itter_Add(Weapons,Iter_Count(Weapons)+1);

    GetPlayerPos(playerid, WeaponInfo[Iter_Count(Weapons)][wPos][0], WeaponInfo[Iter_Count(Weapons)][wPos][1], WeaponInfo[Iter_Count(Weapons)][wPos][2]);
    WeaponInfo[Iter_Count(Weapons)][wObject] = GunObjects[gunID][0];

    WID = CreateObject(GunObjects[gunID][0], WeaponInfo[Iter_Count(Weapons)][wPos][0], WeaponInfo[Iter_Count(Weapons)][wPos][1], WeaponInfo[Iter_Count(Weapons)][wPos][2]-1,93.7,120.0,120.0);

    WeaponInfo[Iter_Count(Weapons)][wObjectID] = WID;
    WeaponInfo[Iter_Count(Weapons)][wAmmo] = gunAmmo;
    WeaponInfo[Iter_Count(Weapons)][wDropped] = gunID;

    return 1;
}


COMMAND:createhouse(playerid, cmdtext[], params[])
{

//if(PlayerInfo[playerid][AdminLevel] < 4) return SendClientMessage(playerid,COLOR_WHITE,"SERVER: Unknown command.");
//    if(AccountData[playerid][AdminLevel] > 3) return SendError(playerid, "You must be a level 3 admin");
    ShowPlayerDialog(playerid, DIALOG_CREATE_HOUSE, DIALOG_STYLE_INPUT, "Create house!","Enter the sell price.", "Submit", "Cancel");
    return 1;
}

COMMAND:createfaction(playerid, params[])
{
    new name[40];
    new type;
    new leader;
    if(sscanf(params, "uis[40]", leader, type, name)) return SendClientMessage(playerid, COLOR_RED, "{E80FCC}USAGE:{FFFFFF} /createfaction <leader> <type> <Name>"),SendClientMessage(playerid, COLOR_RED, "{E80FCC}AVAILABLE TYPES:{FFFFFF} Police, Gang, News, Medic");
	if(PlayerInfo[leader][pFaction] > 0) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}He must leave his faction.");
	new s_str[128];
	GetPlayerName(leader, PlayerName, 24);
	format(s_str, 128, "{FFFD96}INFO:{FFFFFF} You have created faction {FFFD96}%s{FFFFFF}, leader: {FFFD96}%s", name, PlayerName);
	SendClientMessage(playerid, COLOR_YELLOW, s_str);
	CreateFaction(leader, name, type);
    return 1;
}

COMMAND:createbuilding(playerid, params[])
{
    new buName[35];
    new INT;
    if(sscanf(params, "is[35]", INT, buName)) return SendClientMessage(playerid, COLOR_RED, "{E80FCC}USAGE:{FFFFFF} /createbuilding <interior> <Name>");
    CreateBuilding(playerid, INT, buName);
    return 1;
}

COMMAND:createbusiness(playerid, params[])
{
    new name[64];
    new interior;
    new price;
    new type;
    
    if(sscanf(params, "iiis[64]", interior, price, type, name)) return SendClientMessage(playerid, COLOR_RED, "{E80FCC}USAGE:{FFFFFF} /createbusiness <interior> <price> <type> <name>"), SendClientMessage(playerid, COLOR_RED, "{E80FCC}Available types:{FFFFFF} 1 - Weapons 2 - 24/7 3 - Bar");

	CreateBusiness(playerid, price, type, interior, name);
    return 1;
}

COMMAND:park(playerid)
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You must be in a vehicle.");
    new VehID;
    VehID = GetPlayerVehicleID(playerid);
    if(VehicleInfo[VehID][vOwner] != PlayerInfo[playerid][cSQLID]) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You must be owner of this vehicle, in order to park it.");
    GetVehiclePos(VehID, VehicleInfo[VehID][vPos][0], VehicleInfo[VehID][vPos][1], VehicleInfo[VehID][vPos][2]);
    GetVehicleZAngle(VehID, VehicleInfo[VehID][vPos][3]);
    SendClientMessage(playerid, COLOR_WHITE, "Your vehicle has been parked, the vehicle now will respawn here!");
    SavePlayerVehicle(VehID);
    return 1;
}

CMD:buyvehicle(playerid, params[])
{
	if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You must be in a vehicle.");
    new VehID;
    VehID = GetPlayerVehicleID(playerid);
    if(VehicleInfo[VehID][vbuyable] != 1) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}This vehicle is not for sale.");
	if(GetPlayerMoney(playerid) < VehicleInfo[VehID][vprice]) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}Sorry, you can't afford this car.");
    VehicleInfo[VehID][vOwner] = PlayerInfo[playerid][cSQLID];
    GivePlayerMoney(playerid, - VehicleInfo[VehID][vprice]);
    VehicleInfo[VehID][vbuyable] = 0;
    Delete3DTextLabel(BuyableVehicle[VehID]);
    SendClientMessage(playerid, COLOR_YELLOW, "Congratulations{FFFFFF}, you have{FFFD96}bought {FFFFFF} this vehicle.");
    SendClientMessage(playerid, COLOR_YELLOW, "{FFFD96}HINT:{FFFFFF} You may view {FFFD96}/help {FFFFFF} for vehicle commands.");
    SavePlayerVehicle(VehID);
	return 1;
}

COMMAND:speed(playerid, params[])
{
	g_fSpeedCap[ playerid ] = floatstr( params );
	return true;
}

COMMAND:giveplayermoney(playerid, params[])
{
	 GivePlayerMoney(playerid, 10000000);
}



COMMAND:vcp(playerid, params[])
{
	if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You must be in a vehicle.");
	if(GetPVarInt(playerid, "VEHICLE_CPU") == 1) return true;
	TextDrawShowForPlayer(playerid, VehicleCPU[playerid]);
	SetPVarInt(playerid, "VEHICLE_CPU", 1);
	SetPVarInt(playerid, "VEHICLE_OPTION", 1);
	TogglePlayerControllable(playerid, false);
	UpdateVehicleCPU(playerid);
	SendClientMessage(playerid, COLOR_GREEN, "{FFFFFF}To close vehicle control panel press {00F52D}LMB{FFFFFF}.");
	return 1;
}

COMMAND:sellcar(playerid, params[])
{
	new string[128];
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You must be in a vehicle.");
    new VehID;
    new uID;
    new Price;
    VehID = GetPlayerVehicleID(playerid);
    if(GetPVarInt(playerid, "Offerer") != -1) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You are selling a vehicle already.");
    if(VehicleInfo[VehID][vOwner] != PlayerInfo[playerid][cSQLID]) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You are not the owner of this vehicle.");
    if(sscanf(params, "ui", uID, Price)) return SendClientMessage(playerid, 0x00FF9DFF, "{E80FCC}USAGE:{FFFFFF} /sellcar <Name/PlayerID> <Price>");
    if(GetPlayerMoney(uID) < Price ) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}That player doesn't have that much money.");
    if (!ProxDetectorS(8.0, playerid, uID)) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}Buyer must be near you.");
    if(uID == playerid) SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}What are you doing?");
    if(Price == 0 || Price < 1) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}Invalid amount.");

    SetPVarInt(uID, "SellCar", VehID);
    SetPVarInt(uID, "Offerer", playerid);
    SetPVarInt(playerid, "Offerer", uID);
    SetPVarInt(uID, "Veh_Price", Price);

    new OtherName[24];
    new VehName2[24];
	new m_str[128];

	GetPlayerName(playerid, PlayerName, 24);
	GetPlayerName(uID, OtherName, 24);
    GetVehicleName(VehicleInfo[VehID][vModel], VehName2, 24);
    format(m_str, 128, "You have offered your{FF0000}%s{FFFFFF} to {FFFD96}%s{FFFFFF} for {FF0000}%s{FFFFFF}..", VehName2, OtherName, FormatMoney(Price));
    SendClientMessage(playerid, COLOR_YELLOW, m_str);
    format(m_str, 128, "You have offered{FF0000}%s{FFFFFF} has offered you his vehicle {FFFD96}%s{FFFFFF} for {FF0000}%s{FFFFFF}. /acceptvehicle to accept this offer, /canceloffer to cancel this offer.", PlayerName, VehName2, FormatMoney(Price));
    SendClientMessage(uID, COLOR_YELLOW, m_str);
    //SendFormattedMessage(uID, COLOR_LIGHTBLUE, "%s has offered you his vehicle %s for %s. /acceptvehicle to accept this offer, /canceloffer to cancel this offer.", PlayerName, VehName, FormatMoney(Price));
	format(string, sizeof(string), "%s hands some agreement papers to %s.", PlayerName, OtherName);
    SendLocalMessage(playerid, string, 20.0, COLOR_ME);
    return 1;
}


COMMAND:createvehicle(playerid, params[])
{
    new    model;
    new    price;
    new    buyable;
    new    rent;
    new    faction;
    new    color1;
    new    color2;
    if(sscanf(params, "iiiiiii", model, price, buyable, rent, faction, color1, color2)) return SendClientMessage(playerid, COLOR_RED, "{E80FCC}USAGE:{FFFFFF} /createvehicle <model> <price> <buyable> <rent> <faction> <color1> <color2>  - ");
    if(buyable == 1 && rent > 0) return 1;
    CreateVehicleEx(playerid, model, price, buyable, rent, faction, color1, color2);
    //SendFormattedMessage(playerid, COLOR_YELLOW, "Vehicle Model: %d has been created!", model);
    return 1;
}

COMMAND:canceloffer(playerid, params[])
{
    new string[128];
    if(GetPVarInt(playerid, "SellCar") == 0)  return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}No-one is selling an vehicle to you.");
    new Offerer = GetPVarInt(playerid, "Offerer");

    SendClientMessage(Offerer, COLOR_LIGHTBLUE, "He has denied the offer.");
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "You have canceled the offer.");

    GetPlayerName(playerid, PlayerName, 24);
    format(string, sizeof(string), "%s denies the offer.", PlayerName);
    SendLocalMessage(playerid, string, 20.0, COLOR_ME);

    SetPVarInt(playerid, "SellCar", 0);
    SetPVarInt(playerid, "Offerer", 0);
    SetPVarInt(Offerer, "Offerer", 0);
    SetPVarInt(playerid, "Veh_Price", 0);
    return 1;
}


COMMAND:acceptvehicle(playerid, params[])
{
    new string[128];
    if(GetPVarInt(playerid, "SellCar") == 0) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}No-one is selling an vehicle to you.");
    new Offerer = GetPVarInt(playerid, "Offerer");
    if(!IsPlayerInAnyVehicle(Offerer)) return SendClientMessage(playerid, COLOR_RED,"He must be in a vehicle!");
    new VehID;
    VehID = GetPlayerVehicleID(Offerer);
    if(VehicleInfo[VehID][vOwner] != PlayerInfo[Offerer][cSQLID]) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}Offerer must be in the vehicle he is trying to sell.");

    GivePlayerMoney(Offerer, GetPVarInt(playerid, "Veh_Price"));
    GivePlayerMoney(playerid, GetPVarInt(playerid, "Veh_Price"));

    RemovePlayerFromVehicle(Offerer);
    VehicleInfo[VehID][vOwner] = PlayerInfo[playerid][cSQLID];
    //EUM_ShowForPlayer(playerid, 1, "~p~Congratulations!", "You have bought a new vehicle! /help vehicle for more info!");

	GetPlayerName(playerid, PlayerName, 24);
    SendClientMessage(Offerer, COLOR_LIGHTBLUE, "The vehicle has been sold!");
    format(string, sizeof(string), "%s signs the agreement and hands it back.", PlayerName);
    SendLocalMessage(playerid, string, 20.0, COLOR_ME);

    SetPVarInt(playerid, "SellCar", 0);
    SetPVarInt(playerid, "Offerer", 0);
    SetPVarInt(Offerer, "Offerer", 0);
    SetPVarInt(playerid, "Veh_Price", 0);
    return 1;
}

COMMAND:lock(playerid, params[])
{
    new string[128];
    new VehID = GetClosestVeh(playerid, 60.0);
    if(VehID == INVALID_VEHICLE_ID) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}There is no vehicles near you.");
    if(VehicleInfo[VehID][vOwner] != PlayerInfo[playerid][cSQLID] && VehicleInfo[VehID][vRented] != PlayerInfo[playerid][cSQLID]) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You don't have keys for this vehicle.");
	GetPlayerName(playerid, PlayerName, 24);
    new
			        engine,
			   		light,
			    	alarm,
					doors,
					bonnet,
					boot,
					objective;
					
    GetVehicleParamsEx(VehID, engine,light,alarm,doors,bonnet,boot,objective);
	if(!IsPlayerInAnyVehicle(playerid)) {
        if(VehicleInfo[VehID][vLock] == 1) {
            VehicleInfo[VehID][vLock] = 0;
            format(string, sizeof(string), "%s inserts car key's in the lock and unlocks the car.", PlayerName);
            SendLocalMessage(playerid, string, 20.0, COLOR_ME);
            SavePlayerVehicle(VehID);
            SetVehicleParamsEx(VehID,engine,light,alarm,VEHICLE_PARAMS_OFF,bonnet,boot,objective);
            return 1;
        }
        if(VehicleInfo[VehID][vLock] == 0) {
            VehicleInfo[VehID][vLock] = 1;
            format(string, sizeof(string), "%s inserts car key's in the lock and locks the car.", PlayerName);
            SendLocalMessage(playerid, string, 20.0, COLOR_ME);
            SavePlayerVehicle(VehID);
            SetVehicleParamsEx(VehID,engine,light,alarm,VEHICLE_PARAMS_ON,bonnet,boot,objective);
            return 1;
        }
    }
    else {
        VehID = GetPlayerVehicleID(playerid);
        if(VehicleInfo[VehID][vLock] == 1) {
            VehicleInfo[VehID][vLock] = 0;
            format(string, sizeof(string), "%s reaches for the lock and unlocks the car.", PlayerName);
            SendLocalMessage(playerid, string, 20.0, COLOR_ME);
            SavePlayerVehicle(VehID);
            SetVehicleParamsEx(VehID,engine,light,alarm,VEHICLE_PARAMS_OFF,bonnet,boot,objective);
            return 1;
        }
        if(VehicleInfo[VehID][vLock] == 0) {
            VehicleInfo[VehID][vLock] = 1;
            format(string, sizeof(string), "%s reaches for the lock and locks the car.", PlayerName);
            SendLocalMessage(playerid, string, 20.0, COLOR_ME);
            SavePlayerVehicle(VehID);
            SetVehicleParamsEx(VehID,engine,light,alarm,VEHICLE_PARAMS_ON,bonnet,boot,objective);
            return 1;
        }
        return 1;
    }

    return 1;
}


CMD:charactermenu(playerid, params[])
{
    	TogglePlayerSpectating(playerid,1);
    	ShowCharactersMenu(playerid);
    	// Clear all character's variables
	    PlayerInfo[playerid][cSQLID] = 0;
	    SetPVarInt(playerid, "SPAWNED", 0);
	    ResetPlayerMoney(playerid);
	    SetPVarInt(playerid, "SPAWNED", 0);
		return 1;
}

CMD:r(playerid, params[])
{
	if(PlayerHasItem(playerid,"Walkie Talkie") == 0) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You don't have walkie talkie.");
	if(strlen(params) < 2) return SendClientMessage(playerid, COLOR_RED, "{FF0000}USAGE: {FFFFFF}/r <message>");
	if(PlayerInfo[playerid][pRadio] == 0) return SendClientMessage(playerid, COLOR_RED, "{FF0000}WARNING: {FFFFFF}You must configure your walkie talkie first. ( In inventory )");
	new m_str[128];
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	format(m_str, 128, "{33CCFF}WT(%i) %s: %s", PlayerInfo[playerid][pRadio], PlayerName, params);
	foreach(Player, i)
	{
		   if(PlayerInfo[i][pRadio] == PlayerInfo[playerid][pRadio])
		   {
				SendClientMessage(i, COLOR_GREY, m_str);
		   }
	}
	return true;
}

CMD:me(playerid, params[])
{
	if(strlen(params) < 2) return SendClientMessage(playerid, COLOR_RED, "{FF0000}USAGE: {FFFFFF}/me <action>");
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	format(str, sizeof(str), "%s %s", PlayerName, params );
    SendLocalMessage(playerid, str, 20.0, 0x83bfbfAA);
    return 1;
}

CMD:o(playerid, params[])
{
	if(strlen(params) < 2) return SendClientMessage(playerid, COLOR_RED, "{FF0000}USAGE: {FFFFFF}/o <text>");
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	format(str, sizeof(str), "{FFB200}(( {FFFFFF}OOC %s: %s {FFB200})){FFFFFF}", PlayerName, params );
	SendClientMessageToAll(COLOR_WHITE, str);
	return 1;
}

CMD:do(playerid, params[])
{
	if(strlen(params) < 2) return SendClientMessage(playerid, COLOR_RED, "{FF0000}USAGE: {FFFFFF}/do <action>");
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	format(str, sizeof(str), "%s (( %s ))", params,  PlayerName );
    SendLocalMessage(playerid, str, 20.0, 0x83bfbfAA);
    return 1;
}

CMD:b(playerid, params[])
{
	if(strlen(params) < 2) return SendClientMessage(playerid, COLOR_RED, "{FF0000}USAGE: {FFFFFF}/b <text>");
	GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
    format(str, sizeof(str), "(( %s: %s ))", PlayerName, params );
    SendLocalMessage(playerid, str, 20.0, COLOR_WHITE);
    return 1;
}
CMD:fightingstyle(playerid, params[])
{
		format(query, sizeof(query), "SELECT * FROM fightstyles WHERE id = %i", PlayerInfo[playerid][cSQLID]);
		mysql_query(query, THREAD_FIGHTINGSTYLE, playerid);
		return true;
}
/*
CMD:myfaction(playerid)
{
	if(PlayerInfo[playerid][pFaction] == 0) return SendClientMessage(playerid, COLOR_RED, "{FF0000}ERROR: {FFFFFF}You must be in a faction\gang.");
	return 1;
}
*/
CMD:inventory(playerid)
{
    ShowInventory(playerid);
    return 1;
}
CMD:items(playerid)
{
    ShowInventory(playerid);
    return 1;
}
